package checkers3d.logic;

import checkers3d.presentation.*;
import java.awt.*;
import java.util.*;

public class GameMaster//Manages the current game and all GUIContainers.
{
    private boolean alive;
    private Stack<GUIContainer> GUIContainers;
    private static final GameMaster INSTANCE = new GameMaster();

    private GameMaster()//Constructor. See singleton pattern.
    {
        GUIContainers = new Stack<GUIContainer>();
        alive = true;

        addGUIContainer(new MenuMain(GameEngine.WINDOW_SIZE));
    }

    public static GameMaster getInstance()//See singleton pattern.
    {
        return INSTANCE;
    }

    public GUIContainer getTopGUIContainer()//Returns visible GUIContainer.
    {
        return GUIContainers.peek();
    }

    public void addGUIContainer(GUIContainer container)
    {
        GUIContainers.push(container);
    }

    public void removeTopGUIContainer()
    {
        GUIContainers.pop();
    }

    public void onClick(Point position)//Directs event
    {
        GUIContainers.peek().onClick(position);
    }

    public void onKeyPress(char key)//Directs event
    {
        GUIContainers.peek().onKeyPress(key);
    }

    public boolean getAlive()//Returns if the game is still active.
    {
        return alive;
    }

    public void setAlive(boolean alive)//Sets if the game is active
    {
        this.alive = alive;
    }

    //notes elapsed time
    public void tick(int ms)
    {
        getTopGUIContainer().tick(ms);
    }

    //returns stack GUIContainers
    public Stack<GUIContainer> getGUIContainers()
    {
        return GUIContainers;
    }
}


